package com.digoyo.hr.controller.system.basic;

import com.digoyo.hr.model.Menu;
import com.digoyo.hr.model.RespBean;
import com.digoyo.hr.model.Role;
import com.digoyo.hr.service.MenuService;
import com.digoyo.hr.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Daniel
 * @Description:
 * @Date: Created in 10:56 AM 2020/6/18
 * @Modified By:
 */

@RestController
@RequestMapping("/system/basic/permiss")
public class PermissController {
    @Resource
    RoleService roleService;
    @Resource
    MenuService menuService;
    @GetMapping("/")
    public List<Role> getAllRoles(){
        return roleService.getAllRoles();
    }

    @GetMapping("/menus")
    public List<Menu> getAllMenus(){
        return menuService.getAllMenus();
    }
    @GetMapping("/mids/{rid}")
    public List<Integer> getMidsByRid(@PathVariable  Integer rid){
        return menuService.getMidsByRid(rid);
    }
    @PutMapping
    public RespBean updateMenuRole(Integer rid, Integer[] mids){
        if (menuService.updateMenuRole(rid,mids)) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
    @PutMapping("/role")
    public RespBean addRole(@RequestBody Role role){
        if (roleService.addRole(role) == 1) {
            return RespBean.ok("添加成功");
        } else {
            return RespBean.error("添加失败");
        }
    }
}
